'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 获取随机合成装备
 * @author sundbcn@gmail.com (sun debing)
 */

var _ = require('lodash');
var equipConf = require('../config/equipConf');
var randomUtil = require('../util/randomUtil');
var genRewardService = require('./genRewardService');

/**
 * 随机合成装备
 * @param {[type]} compose_id [description]
 */
exports.getRandomEquip = function (compose_id) {
    var equip_random_conf = equipConf.getRandomEquip(compose_id);
    return genRewardService.generateReward(randomUtil.sample(equip_random_conf));
};

/**
 * 获取合成装备的概率，合成id, 扣除金币
 */
exports.getComposeRelatedInfo = function (job_type, equip_quality_list) {
    job_type = job_type;
    var compose_id;
    var probability;
    var sub_gold;
    var equip_compose_list = equipConf.getComposeEquipConf(_.first(equip_quality_list));

    // 获取合成装备的概率，合成id, 扣除金币
    _.some(equip_compose_list, function (equip_compose_item) {
        if (equip_compose_item.profession == job_type) {
            compose_id = equip_compose_item.compose_id;
            probability = equip_compose_item.probability;
            sub_gold = equip_compose_item.cost_gold;
            return;
        }
    });
    return {
        compose_id: compose_id,
        probability: probability,
        sub_gold: sub_gold
    };
};
